package com.youlv.yl.controller;


import com.youlv.yl.config.SystemConfig;
import com.youlv.yl.dto.HotelOrderCartDto;
import com.youlv.yl.dto.HotelOrderGoodsDto;
import com.youlv.yl.service.intf.HotelOrderService;
import com.youlv.yl.vo.R;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 订单表  前端控制器
 * </p>
 *
 * @author fenghe
 * @since 2022-01-25
 */
@RestController
@RequestMapping("/yl/hotelOrder")
@Api(value = "实现订单相关操作", tags = "实现了订单相关操作")
@CrossOrigin
public class HotelOrderController {

    @Autowired
    private HotelOrderService service;

    /** 下单-购物车*/
    @PostMapping("saveco.do")
    public R save(@RequestBody HotelOrderCartDto dto, HttpServletRequest request) {
        String token = request.getHeader(SystemConfig.REQ_HEADER_TOKEN);
        dto.setToken(token);
        return service.save(dto);
    }

    /** 下单商品详情*/
    @PostMapping("savego.do")
    public R save(@RequestBody HotelOrderGoodsDto dto, HttpServletRequest request) {
        String token = request.getHeader(SystemConfig.REQ_HEADER_TOKEN);
        dto.setToken(token);
        return service.save(dto);
    }

    /** 查询订单列表*/
    @GetMapping("list.do")
    public R all(Integer type, HttpServletRequest request) {
        String token = request.getHeader(SystemConfig.REQ_HEADER_TOKEN);
        return service.queryMy(token, type);
    }

    /** 订单取消*/
    @GetMapping("cancel.do")
    public R cancel(Long oid) {
        return service.cancel(oid);
    }
}
